<template>
	<view>
		<cu-custom bgColor="bg-gradual-blue" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">添加地址</block>
		</cu-custom>

		<view class="main">
			<view class="cu-form-group">
				<view class="title">收货人姓名</view>
				<input placeholder="请输入收货人姓名" v-model="address.shippingUser"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">省</view>
				<input placeholder="输入省" v-model="address.province"></input>
				<text class='cuIcon-locationfill text-orange'></text>
			</view>
			<view class="cu-form-group">
				<view class="title">城市</view>
				<input placeholder="输入城市" v-model="address.city"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">区</view>
				<input placeholder="请输入小区信息" v-model="address.district"></input>
			</view>
			<view class="cu-form-group margin-top">
				<view class="title">收货地址</view>
				<input placeholder="输入地址 " v-model="address.address"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">收货人手机号</view>
				<input placeholder="请输入手机号" v-model="address.shippingPhone"></input>
				<view class="cu-capsule radius">
					<view class='cu-tag bg-blue '>
						+86
					</view>
					<view class="cu-tag line-blue">
						中国大陆
					</view>
				</view>
			</view>
			<view class="cu-form-group flex justify-center">
				<button class="cu-btn bg-blue" @click="add">添加</button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				address: {
					address: '',
					city: '',
					customerId: 0,
					district: '',
					id: 0,
					isDefault: 0,
					modifiedTime: '2020-08-01T04:21:10.133Z',
					province: '',
					shippingPhone: '',
					shippingUser: ''
				}
			}
		},
		methods: {
			add(){
				let empty;
				empty = this.address.address =='' || this.address.city==''||
						this.address.district =='' || this.address.province ==''||
						this.address.shippingPhone == '' || this.address.shippingUser == '';
				if(empty){
					uni.showToast({
						title:'所填信息不能为空！'
					})
				}else{
					this.$storage.getStorage('user')
					.then(res =>{
						this.address.customerId = res.data.id;
						return this.$api.api_addAddress(this.address)
					})
					.then(res =>{
						uni.showToast({
							title:'添加成功！',
							duration:3000
						})
						uni.navigateTo({
							url:'../submit/submit'
						})
					})
					.catch(err =>{
						console.log(err)
					})
				}
			}
		}
	}
</script>

<style>

</style>
